package com.xcity.game.combat.skill.impl;

import java.util.List;

import com.alibaba.fastjson.annotation.JSONField;
import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.Combat;
import com.xcity.game.combat.CombatUtils;
import com.xcity.game.combat.buff.CombatBuff;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.skill.Skill;

/**
 * 一笑倾城<br/>
 * 针对敌方全员释放魅惑攻击，有{0=30#0}%几率另对方混乱
 * @author yang.li
 *
 */
public class COMBAT_SKILL_90107 extends CombatSkill {

	public COMBAT_SKILL_90107(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
		int n = (int) skill.getParameter(0);
		List<CombatUnit> targets = action.target.all();
		for (int i = 0; i < targets.size(); i++) {
			CombatUnit target = targets.get(i);
			if (!target.isDied()) {
				ActionEffect effect = action.addTarget(target);
				target = effect.getUnit(); // 修正目标
//				int damage = CombatUtils.calcCommonMagicDamage(action.unit, target);
//				effect.effect(CombatAttribute.Type.HP, -damage);
				CombatUtils.calcMagicAttack(effect);
				// debuff
				if (Combat.RND.nextInt(GameStaticConfig.percentBase) < n) {
					action.addBuff(new BUFF(skill, target));
				}
			}
		}
	}
	
	static class BUFF extends CombatBuff {
		public BUFF(Skill skill, CombatUnit owner) {
			super(skill.getTemplate().getCombatBuff(), owner, 1);
		}
		@Override
		public CombatUnit preTarget(Action action) {
			active = true;
			CombatUnit target = action.ref().ref().getUnitRandomly();
			return target;
		}
		@Override
		public void preDamage(ActionEffect effect) {
		}
		@Override
		@JSONField(serialize = false)
		public boolean isDebuff() {
			return true;
		}
	}

}
